package javacode.chapter05;

public class Example5_2 {
    public static void main(String[] args) {
        // 冒泡排序
        int[] numbers = new int[]{6, 9, 7, 4, 3};
        //输出排序前的序列
        for (int i = 0; i < 5; i++) {
            System.out.print(numbers[i] + " ");
        }

        // 对数组进行冒泡排序
        for (int i = 0; i < numbers.length - 1; i++) {
            for (int j = 0; j < numbers.length - 1 - i; j++) {
                if (numbers[j] > numbers[j + 1]) {
                    int temp = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = temp;
                }
            }
        }

        // 输出排序后的序列
        System.out.println();
        for (int i = 0; i < numbers.length; i++) {
            System.out.print(numbers[i] + " ");
        }
    }
}
